<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var stopReason = document.getElementById("stopReason");
		<c:if test="${empty contract.receivable || contract.receivable > 0 || contract.invoiceCost != contract.contractCost}">
		if(stopReason.value == ""){
			alert("终止原因<fmt:message key='common.message.empty'/>");
			return false;
		}
		</c:if>
		return true;
	}

	function back(){
		var sign = "<c:out value='${sign}'/>";
		var url = "./contract.do";
		if(sign == 1){
			url = "./contract.do";//返回销售合同页面
		}else if(sign == 2){
			url = "./contractBackCost.do";//返回应收帐款页面
		}else if(sign == 3){
			url = "./contractBackCost.do?action=deptBackCostManage";//返回部门应收帐款页面
		}
		window.location.href = url;
		window.location.target = "main";
	}
	
	function deleteAdded(){
		var currentValue = document.all.addedId.value;
		if(currentValue != ""){
			document.stopContractForm.action = "./contract.do?action=deleteStopContractAdded&addedId="+currentValue;
			document.stopContractForm.target = "main";
			document.stopContractForm.submit();
		}else{
			alert("请选择要删除的附件！");
		}
	}
	
	function save(){
		if(checkForm()){
			document.stopContractForm.action = "./contract.do?action=stopContract";
			document.stopContractForm.target = "main";
			document.stopContractForm.submit();
			
			document.getElementById("saveBtn").href = "#";
		}
	}
	
	function initPage(){
		if("<c:out value='${result}'/>" == 1){
			alert("合同已终止！");
		}
		if("<c:out value='${uploadResult}'/>" == 3){
			alert("终止失败：上传文件大小不能超过10M!");
		}else if("<c:out value='${uploadResult}'/>" == 4){
			alert("终止失败：请勿重复上传附件!");
		}
		if("<c:out value='${deleteResult}'/>" == 1){
			alert("删除附件成功！");
		}
		
		document.getElementById("saveBtn").href = "javascript:save();";
	}
-->
</script>
</head>
<body onload="initPage()">
<form name="stopContractForm" action="" method="post" enctype="multipart/form-data">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab">终止合同</td>
					</tr>
					<tr>
						<td align="center" valign="bottom">
							<button class="btn_submit" onclick="save()" hidefocus="true">提交</button>&nbsp;&nbsp;
							<button class="btn_back" onclick="back()" hidefocus="true">取消并返回</button>
						</td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td>
							<table class="table_add">
								<tr>
									<td class="title">客户名称：</td>
									<td>
										${contract.customerName}
										<input id="customerId" name="customerId" type="hidden" value="${contract.customerId}"/>
									</td>
									<td class="title">合同名称：</td>
									<td >
										${contract.contractName}
										<input id="id" name="id" type="hidden" value="${contract.id}"/>
									</td>
								</tr>
								<tr>
									<td class="title">合同编号：</td>
									<td >${contract.contractCode}</td>
									<td class="title">销售代表：</td>
									<td >${contract.salePerson}</td>
								</tr>
								<tr>
									<td class="title">审核人：</td>
									<td >${contract.auditPerson}</td>
									<td class="title">审核日期：</td>
									<td ><fmt:formatDate value="${contract.auditDate}" pattern="yyyy-MM-dd"/></td>
								</tr>
								<tr>
									<td class="title">备注：</td>
									<td colspan="3"><pre>${contract.contractDesc}</pre></td>
								</tr>
								<c:if test="${empty contract.receivable || contract.receivable > 0 || contract.invoiceCost != contract.contractCost}">
								<tr>
									<td class="title">终止原因：</td>
									<td colspan="3"><textarea id="stopReason" name="stopReason" class="textarea_remark" wrap="hard">${contract.stopReason}</textarea></td>
								</tr>
								</c:if>
								<tr>
									<td rowspan="2" style="height: 60px;" class="title"><font style="font-size: 10px;">(附件 &lt; 10M)</font>&nbsp;&nbsp;上传附件：</td>
									<td colspan="3">
										<select id="addedId" name="addedId" style="width: 86%">
											<c:forEach var="systemFile" items="${contractAddeds}">
											<option value="${systemFile.id}">附件名称：${systemFile.fileName}，上传者：${systemFile.person}，上传时间：<fmt:formatDate value="${systemFile.uploadDate}" pattern="yyyy-MM-dd"/></option>
											</c:forEach>
										</select>&nbsp;
										<input class="" type="button" value=" 删 除 " onclick="deleteAdded()">
									</td>
								</tr>
								<tr>
									<td colspan="4">
										<input id="contents" name="contents" type="file" style="width:96%"/>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td>
							<table class="table_add">
								<tr>
									<td class="title_top" width="60">合同标的</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<td>
							<table class="table_style">
								<tr>
									<td class="title" width="8"></td>
									<td class="title">商品名称</td>
									<!-- 
									<td class="title" width="8%">单位</td>
									<td class="title" width="12%">单价(元)</td>
									 -->
									<td class="title" width="8%">数量</td>
									<td class="title" width="12%">折扣率(%)</td>
									<td class="title" width="15%">折扣后的金额(元)</td>
									<td class="title" width="12%">成本(元)</td>
									<td class="title" width="12%">毛利(元)</td>
								</tr>
								<c:forEach var="contractDetail" items="${contractDetails}">
								<tr onmouseover="onmousemoveChange(this,'img${contractDetail.id}')" onmouseout="onmouseoutChange(this,'img${contractDetail.id}')">
									<td height="16" width="8" align="right"><img id="img${contractDetail.id}" src="./images/table_sign2.bmp"></td>
									<td align="left">${contractDetail.purchaseDesc}</td>
									<!-- 
									<td>${contractDetail.unit}</td>
									<td>${contractDetail.price}</td>
									 -->
									<td>${contractDetail.num}</td>
									<td>${contractDetail.discount}</td>
									<td>${contractDetail.costValue}</td>
									<td>${contractDetail.costs}</td>
									<td>${contractDetail.prossProfit}</td>
								</tr>
								</c:forEach>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<input id="sign" name="sign" type="hidden" value="${sign}"/>
</form>
</body>
</html>